<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
</head>
<body>
<%
	try {
		//Class.forName("com.mysql.jdbc.Driver");
		Context initCtx = new InitialContext();
		Context ctx = (Context)initCtx.lookup("java:comp/env");
		//get conneticon object
		Object obj = (Object)ctx.lookup("jdbc/mysql");
		//
		javax.sql.DataSource ds = (javax.sql.DataSource)obj;
		Connection conn = ds.getConnection();
		Statement stmt = conn.createStatement();
		String sql = "SELECT * FROM users";
		ResultSet rs = stmt.executeQuery(sql);
		out.println("<table>");
		out.println("<tr>");
		out.println("<td>" + "用户id：</td>");
		out.println("<td>" + "用户名：</td>");
		out.println("<td>" + "年龄：</td>");
		out.println("</tr>");
		while(rs.next()) {
			out.println("<tr>");
			out.println("<td>" + rs.getShort("id") + "</td>");
			out.println("<td>" + rs.getString(2) + "</td>");
			out.println("<td>" + rs.getString("age") + "</td>");
			out.println("</tr>");
		}
		out.println("</table>");
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
</body>
</html>